﻿# 进行服务的唤醒，防止调用的时候报错，只相应，不追求接口成功
$configs = @(
    @{ Name = "ApiManage";      Port = 8016; Type = 3; Url = "/api/SysNotice/PushMsg" }
    @{ Name = "AuthCenterAPI";  Port = 8015; Type = 3; Url = "/api/Auth/GetUserToken" }
    @{ Name = "Base";           Port = 8001; Type = 1; Url = "" }
    @{ Name = "BaseAPI";        Port = 7001; Type = 3; Url = "/api/Auth/GetToken" }
    @{ Name = "CIS";            Port = 8003; Type = 1; Url = "" }
    @{ Name = "CISAPI";         Port = 7003; Type = 3; Url = "/api/Auth/GetToken" }
    @{ Name = "EMR";            Port = 8005; Type = 1; Url = "" }
    @{ Name = "EmrStatic";      Port = 8020; Type = 2; Url = "" }
    @{ Name = "Herp";           Port = 8007; Type = 1; Url = "" }
    @{ Name = "his.baseapi";    Port = 8017; Type = 3; Url = "/api/sysuser/GetSysUserPage" }
    @{ Name = "MRMS";           Port = 8008; Type = 1; Url = "" }
    @{ Name = "MRQC";           Port = 8009; Type = 1; Url = "" }
    @{ Name = "OR";             Port = 8006; Type = 1; Url = "" }
    @{ Name = "ORAPI";          Port = 7006; Type = 3; Url = "/api/Auth/GetToken" }
    @{ Name = "PDS";            Port = 8004; Type = 1; Url = "" }
    @{ Name = "PDSAPI";         Port = 7004; Type = 3; Url = "/api/Auth/GetToken" }
    @{ Name = "Report";         Port = 8000; Type = 1; Url = "" }
    @{ Name = "Sett";           Port = 8002; Type = 1; Url = "" }
    @{ Name = "SettAPI";        Port = 7002; Type = 3; Url = "/api/Auth/GetToken" }
    @{ Name = "Static";         Port = 8014; Type = 2; Url = "" }
    @{ Name = "Union";          Port = 8018; Type = 1; Url = "" }
)

foreach ($site in $configs) {
    $name = $site.Name
    $port = $site.Port
    $type = $site.Type
    $urlPath = $site.Url
    $baseUrl = "http://localhost:$port"

    switch ($type) {
        1 {
            $url = "$baseUrl/"
            try {
                $response = Invoke-WebRequest -Uri $url -UseBasicParsing -TimeoutSec 5
                Write-Host "✅ [$name] 网页访问成功: $url"
            } catch {
                Write-Warning "❌ [$name] 网页访问失败: $($_.Exception.Message)"
            }
        }

        2 {
            Write-Host "⏭ [$name] 是静态资源，跳过"
        }

        3 {
            if ([string]::IsNullOrWhiteSpace($urlPath)) {
                Write-Warning "⚠️ [$name] 接口地址为空，跳过"
                continue
            }

            $fullUrl = "$baseUrl$urlPath"

            try {
                if ($name -eq "AuthCenterAPI") {
                    # POST 请求唤醒，不需要参数
                    $response = Invoke-RestMethod -Uri $fullUrl -Method Post -Body '{}' -ContentType "application/json" -TimeoutSec 5
                    Write-Host "✅ [$name] POST 请求成功: $fullUrl"
                } else {
                    # 默认 GET 请求
                    $response = Invoke-WebRequest -Uri $fullUrl -UseBasicParsing -TimeoutSec 5
                    Write-Host "✅ [$name] GET 请求成功: $fullUrl"
                }
            } catch {
                Write-Warning "❌ [$name] 接口请求失败: $($_.Exception.Message)"
            }
        }

        default {
            Write-Warning "❓ [$name] 未知类型: $type"
        }
    }

    Start-Sleep -Seconds 1
}